package dp.mobile.eden;

import dp.mobile.entity.saveable.SaveablePlayer;
import dp.mobile.game.Game;
import dp.mobile.game.GameEventListener;
import dp.mobile.game.GameTouchListener;
import dp.mobile.glwrapper.GameRenderer;
import dp.mobile.panel.PanelTouchListener;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.os.Message;
import android.util.Log;
import android.view.View;

public class SkirmishAct extends GameActivityBase implements GameEventListener {
	private static final String TAG = "Skirmish Act";
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.game);

		//initialize components
		initComp();
		// initialize game
		String levelSource = getIntent().getExtras().getString("level");
		Log.d(TAG, "levelSource = " + levelSource);
		mGame = new Game(levelSource);
		mGame.setListener(this);
		
		// initialize screen
		mSurface = (GLSurfaceView)findViewById(R.id.game_screen);
		mSurface.setRenderer(GameRenderer.instance(this, mGame));
		
		// touch handling
		mGameTouchListener	= new GameTouchListener(mGame);
		mPanelTouchListener	= new PanelTouchListener(this, mGame, mTransparentPanel);
		setListener();
		setPausePanelListeners();
		
		// let the game begin!!
		mGame.setSaveable(false);
		mGame.start();
		
		mSaveGameButton.setVisibility(View.GONE);
	}
	
	@Override
	public void onGameOver() {
		if (!isGameOver) {
			if (mGame.getPlayer().getLife() <= 0) {
				SaveablePlayer p = mGame.getPlayer().createSaveable();
				Intent i = new Intent(this, GameOverAct.class);
				i.putExtra(EXTRA_PLAYER_STAT, p);
				i.putExtra(GameOverAct.EXTRA_SKIRMISH, true);
				i.putExtra(GameOverAct.EXTRA_LEVEL_SOURCE, mGame.getLevelSource());
				startActivity(i);
			}
			finish();
			isGameOver = true;
		}
	}
	
	@Override
	public void onDialog(String level, int wave) {
	}
}
